package myself.study.network.tcp.examples.ex01;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

/**
* @Name: TcpServer
* @Description: 案例一：服务端接收键盘录入的数据并打印到控制台
* @Author: 李超	lc_jack@foxmail.com
* @CreateDate: 2017-1-12 下午8:09:29 
* @Version: V1.0
 */
public class TcpServer {
	
	public static void main(String[] args) throws IOException {
		//创建服务端Socket对象
		ServerSocket server = new ServerSocket(12345) ;
		System.out.println("启动tcp服务器...");
		//监听客户端连接
		Socket socket = server.accept() ;
		//使用字符流包装类，对输入流对象进行包装
		BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream())) ;
		//获取客户端发送的数据
		String line = null ;
		while((line = reader.readLine()) != null) {
			//输出到控制台
			System.out.println("from keyword : " + line);
		}
	}

}
